package com.ling.controller;

import com.ling.bean.Answer;
import com.ling.bean.Question;
import com.ling.service.AnswerService;
import com.ling.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class UserAnswerController {
    private final AnswerService answerService;
    private final QuestionService questionService;

    @Autowired
    public UserAnswerController(AnswerService answerService, QuestionService questionService) {
        this.answerService = answerService;
        this.questionService = questionService;
    }

    //跳转到用户回答修改界面
    @GetMapping("/answer/update/{answerId}")
    public String goToAnswerUpdate(@PathVariable String answerId, ModelMap modelMap) {
        Answer answer = answerService.getAnswerById(answerId);
        Question question = questionService.getUserQuestionById(answer.getQuestionid());

        modelMap.addAttribute("answer", answer);
        modelMap.addAttribute("question", question);
        return "answer-update";
    }
}
